package com.course.action;

import java.io.IOException;



import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.course.delegate.UserMgrDelegate;
import com.course.exception.ConnectionException;
import com.course.exception.LoginException;
import com.course.util.UtilConstants;



public class CancelStudentsAction extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
          doPost(request, response);
        }
public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {

             String path="";
             boolean flag=false;

  try{
	    HttpSession hs=request.getSession();
	    String login=(String) hs.getAttribute("user");
	  int cid=Integer.parseInt(request.getParameter("courseid"));
	  int uid=Integer.parseInt(request.getParameter("userid"));
	  
	  try{
	    flag= new UserMgrDelegate().deleteStudent(cid,uid);				  								 
	  }catch (ConnectionException e) {
		e.printStackTrace();
	}catch (LoginException e) {
		e.printStackTrace();
	}
     System.out.println("in Action class vcb..........."+flag);
	   if(flag){
		  request.setAttribute("statuis", UtilConstants._DELETE_STUDENT_SUCCESS);
		  path=UtilConstants._DELETE_STUDENT_HOME;
		 }
	  else {
		  request.setAttribute("statuis", UtilConstants._DELETE_STUDENT_FAILED);
		  path=UtilConstants._DELETE_STUDENT_HOME;
		  }
	  }
  catch (Exception e) {
	  request.setAttribute("statuis", UtilConstants._INVALIED_DATA);
	  path=UtilConstants._DELETE_STUDENT_HOME;
	   e.printStackTrace();
	   }
  RequestDispatcher rd=request.getRequestDispatcher(path);
	rd.forward(request,response);
	}

}
